package cn.pink.gatesrv;

import cn.pink.common.support.tools.cache.CacheTool;
import cn.pink.common.support.tools.cache.ICacheListener;
import cn.pink.common.support.tools.cache.RemoveReason;
import cn.pink.core.*;
import cn.pink.core.config.CacheConfig;
import cn.pink.core.gen.proxy.DistrClass;
import cn.pink.core.gen.proxy.DistrMethod;
import cn.pink.core.support.Log;

/**
 * @Author: pink
 * @Date: 2022/6/21 16:53
 */
@DistrClass(nodeType = NodeType.GATE)
public class GateService extends Service {
    public GateService(Port port) {
        super(port);

        CacheTool.getInstance().registerListener(CacheConfig.SESSION, new ICacheListener() {
            @Override
            public void elementAdd(String key, Object value) {
                Log.gate.info("session put: key={}, value={}", key, value);
            }

            @Override
            public void elementUpdate(String key, Object value, Object oldValue) {
                Log.gate.info("session update: key={}, value={}, oldValue={}", key, value, oldValue);
            }

            @Override
            public void elementRemove(String key, Object oldValue, RemoveReason reason) {
                Log.gate.info("session remove: key={}, oldValue={}, reason={}", key, oldValue, reason);
            }
        });
    }

    @Override
    public Object getId() {
        return RPCProxy.GateServiceProxy.DIST_NAME;
    }

    @DistrMethod
    public void defaultHandler(String str) {

    }
}
